<template>
  <view style="height: 100vh">
    <view class="page" v-if="listdata.length==0 || loginstatus == 1">
      <view class="hezi">
        <view class="hezi_img">
          <image class="kong" src="/static/pages/img/空空的.png"></image>
          <view class="hezi_text">暂无预定订单</view>
        </view>
      </view>

      <navigator class="qyd" @tap="goyuding()">
        <view>去预定</view>
      </navigator>
      <view style="position:absolute;bottom:0;width: 100%">
        <view style="color: #c2c2c2;font-size: 12px;padding: 6px;text-align: center">本系统由集客猫云提供技术支持</view>
      </view>
    </view>

    <view v-else style="display: flex;flex-direction: column;height: 100%">
      <view style="height: calc(100% - 28px);overflow-y: auto">
        <view class="kk" v-for="(item, index) in listdata" :key="index">
          <navigator v-if="item.status == 1" :url="'/packageB/dingdanxiangqing/daixiaofei?id='+item.id">
            <view class="kk_ding">
              <view class="kk_ding_nei">
                <view class="tx">
                  <image style="width: 100%;height: 100%" :src="item.snapshoot.store_info.logo"></image>
                </view>
                <view class="name">{{ item.snapshoot.store_info.name }}</view>
                <view></view>
              </view>

              <view class="zt">待消费</view>
            </view>

            <view class="kk_zhong">
              <view class="zhong_tx">
                <image style="width: 100%;height: 100%" :src="item.snapshoot.cover"></image>
              </view>
              <view>
                <view class="zhong_h1">{{ item.snapshoot.name }}</view>

                <view class="zhong_nk">
                  <view>下单时间：</view>
                  <view>{{ item.create_time }}</view>
                </view>

                <view class="zhong_nk">
                  <view>预定时段：</view>
                  <view>{{ item.start_time + ' 至 ' + item.end_time }}</view>
                </view>

                <view class="zhong_h1">总计 ￥{{ item.price }}</view>
              </view>
            </view>
          </navigator>
          <navigator v-else :url="'/packageB/dingdanxiangqing/xiaofeizhong?id='+item.id">
            <view class="kk_ding">
              <view class="kk_ding_nei">
                <view class="tx">
                  <image style="width: 100%;height: 100%" :src="item.snapshoot.store_info.logo"></image>
                </view>
                <view class="name">{{ item.snapshoot.store_info.name }}</view>
                <view></view>
              </view>

              <view class="zt">消费中</view>
            </view>

            <view class="kk_zhong">
              <view class="zhong_tx">
                <image style="width: 100%;height: 100%" :src="item.snapshoot.cover"></image>
              </view>
              <view>
                <view class="zhong_h1">{{ item.snapshoot.name }}</view>

                <view class="zhong_nk">
                  <view>下单时间：</view>
                  <view>{{ item.create_time }}</view>
                </view>

                <view class="zhong_nk">
                  <view>预定时段：</view>
                  <view>{{ item.start_time + ' 至 ' + item.end_time }}</view>
                </view>

                <view class="zhong_h1">总计 ￥{{ item.price }}</view>
              </view>
            </view>
          </navigator>
          <view class="kk_di" v-if="item.status == 1">
            <view class="di_ksxf" @click="open_damen(item.id,item.order_no)">
              <view>开大门</view>
            </view>
            <view class="di_ksxf" @click="open_bxmen(item.id,item.order_no)">
              <view>开包厢</view>
            </view>
            <view class="di_ksxf" @click="startexpense(item.id)">
              <view>开始消费</view>
            </view>
          </view>
          <view class="kk_di" v-else>
            <view class="di_ksxf" @click="open_damen(item.id,item.order_no)">
              <view>开大门</view>
            </view>
            <view class="di_ksxf" @click="open_bxmen(item.id,item.order_no)">
              <view>开包厢</view>
            </view>

            <view style="background-color: #FF5722" class="di_ksxf" @click="overexpense(item.id)">
              <view>结束消费</view>
            </view>

            <view class="di_ksxf" @click="renew(item.id,item)">
              <view>续费</view>
            </view>
          </view>

          <view class="ge2"></view>
        </view>
      </view>
      <view style="flex: 1;">
        <view style="color: #c2c2c2;font-size: 12px;padding: 6px;text-align: center">本系统由集客猫云提供技术支持</view>
      </view>
    </view>

  </view>
</template>

<script>
import {
  endOrdersEarly,
  houseorderlist,
  houseorderopenDoor,
  orderContinuePay,
  orderContinuePreview,
  startOrdersEarly
} from "@/common/api";


var app = getApp();
export default {
  data() {
    return {
      listdata: [],
      loginstatus: 1,
      someValue: '1',
      page: 1,
      zhifuchenggong: [{
        id: '0',
        name: '逸间云自助台球',
        bxname: '包间-20',
        date: '2022-12-24 20:00 至 2022-12-25 02:00'
      }],

      xiaofeizhong: [{
        id: '1',
        name: '逸间云自助台球',
        bxname: '包间-20',
        date: '2022-12-24 20:00 至 2022-12-25 02:00'
      }],

      zf_list: {
        name: '',
        bxname: '',
        date: ''
      },

      xf_list: {
        name: '',
        bxname: '',
        date: ''
      }
    };
  }
  /**
   * 生命周期函数--监听页面加载
   */,
  onLoad(options) {
    this.setData({
      someValue: '获取到的值'
    });
  },
  onShow: function () {
    this.loginstatus = app.globalData.loginstatus
    this.listdata=[]
    //  console.log('detail',this.loginstatus == 1,this.zhifuchenggong.length,this.xiaofeizhong.length,(this.zhifuchenggong.length==0&&this.xiaofeizhong.length==0) || this.loginstatus == 1)
    this.getdata()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.page = this.page + 1;
    this.getdata()
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  },
  methods: {
    // 去预定
    goyuding() {
      if (app.globalData.loginstatus == 2) {
        uni.switchTab({
          url: "/pages/index/index"
        })
      } else {
        uni.navigateTo({
          url: "/packageC/login/login"
        })
      }
    },
    // 开大门
    open_damen(id, no) {
      uni.showLoading({
        title: '操作中...'
      });

      houseorderopenDoor({
        order_id: id,
        order_no: no,
        onclick: '1'
      }, res => {
        uni.hideLoading();
        uni.showModal({
          title: res.data.msg,
          showCancel: false
        });
      }, fail => {
        uni.hideLoading();
        uni.showModal({
          title: "操作失败",
          showCancel: false
        });
      })
    },
    // 开包厢
    open_bxmen(id, no) {
      uni.showLoading({
        title: '操作中...'
      });
      let _this = this
      houseorderopenDoor({
        order_id: id,
        order_no: no,
        onclick: '2'
      }, res => {
        uni.hideLoading();
        if (res.data.code == 201) {
          uni.showModal({
            title: res.data.msg,
            success: function (ures) {
              if (ures.confirm) {
                _this.tiqianxiaofei(id)
              }
            }
          });
        } else {
          uni.showModal({
            title: res.data.msg,
            showCancel: false
          });
        }
      }, fail => {
        uni.hideLoading();
        uni.showModal({
          title: "操作失败",
          showCancel: false
        });
      })
    },
    // 提前消费
    tiqianxiaofei(id) {
      uni.showLoading({
        title: '操作中...'
      });
      startOrdersEarly({
        order_id: id
      }, res => {
        uni.hideLoading();
        uni.showModal({
          title: res.data.msg,
          showCancel: false
        });
      }, fail => {
        uni.hideLoading();
        uni.showModal({
          title: "操作失败",
          showCancel: false
        });
      })
    },

    // 开始消费
    startexpense(id) {
      let _this = this
      console.log('overexpense', id)
      uni.showModal({
        title: "非预订时间内订单，确定提前消费吗",
        success: function (ures) {
          if (ures.confirm) {
            _this.tiqianxiaofei(id)
          } else {
            console.log('cancel') //点击取消之后执行的代码
          }
        }
      })
    },
    // 结束消费
    overexpense(id) {
      uni.showLoading({
        title: '操作中...'
      });
      let _this = this
      console.log('overexpense', id)
      uni.showModal({
        title: "确定结束消费",
        showCancel: false,
        success: function (ures) {
          if (ures.confirm) {
            endOrdersEarly({
              order_id: id
            }, overres => {
              console.log('overexpenseoverres', overres)
              if (overres.data.code == 0) {
                uni.showModal({
                  title: overres.data.msg,
                  showCancel: false,
                  success: function () {
                    _this.getdata()
                  }
                })
              }
            }, fail => {
              uni.hideLoading();
              uni.showModal({
                title: "操作失败",
                showCancel: false
              });
            })
          }

        }
      })
    },
    // 续费
    renew(id, data) {
      console.log('data', data)
      let _this = this
      uni.navigateTo({
        url: '/packageB/baoxiang/baoxiang?id=' + data.house_id + '&orderendtime=' + data.end_time + '&pagetypetype=2'
      });

    },
    // 获取数据
    getdata() {
      uni.showLoading({
        title: '加载中...'
      });

      houseorderlist({
        status: '2',
        page: this.page
      }, res => {
        this.listdata=this.listdata.concat(res.data.data);
        uni.hideLoading();
      })
    },
  }
};
</script>
<style>
.page {
  height: 100vh;
  background-color: rgb(230, 230, 230);
}

.hezi {
  height: 500rpx;
  padding: 10% 10% 10% 10%;
}

.hezi_img {
  height: 250rpx;
  padding-left: 20rpx;
}

.kong {
  width: 500rpx;
  height: 400rpx;
}

.hezi_text {
  padding: 10rpx 30% 10rpx 30%;
  color: rgb(128, 127, 127);
}

.qyd {
  width: 230rpx;
  height: 100rpx;
  background-color: rgb(221, 177, 140); /* 设置输入框背景色为灰色 */
  border-radius: 10rpx; /* 设置边框圆角 */
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 100rpx 300rpx 0 250rpx;
}

.kk {
  margin: 10rpx 0rpx 20rpx -30rpx;
}

.kk_ding {
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 28rpx;
  font-weight: bold;
}

.kk_ding_nei {
  display: flex;
  align-items: center;
}

.tx {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;

  margin-right: 10rpx;
}

.name {
  width: 360rpx;
  white-space: nowrap; /* 禁止换行 */
  overflow: hidden; /* 超出部分隐藏 */
  text-overflow: ellipsis; /* 超出部分显示省略号 */
}

.zt_cg {
  margin-right: -20rpx;
  color: rgb(131, 127, 127);
}

.kk_zhong {
  display: flex;
  margin: 20rpx 20rpx 20rpx 20rpx;
  padding: 0 0 0 40rpx;
}

.zhong_tx {
  width: 100rpx;
  height: 100rpx;
  background-color: blue;
  margin-right: 10rpx;
  border-radius: 5px; /* 圆角设置为20px */
}

.zhong_h1 {
  font-weight: bold;
  font-size: 30rpx;
  margin-bottom: 10rpx;
}

.zhong_nk {
  display: flex;
  color: rgb(129, 129, 129);
  font-size: 25rpx;
  line-height: 1.5;
}

.kk_di {
  display: flex;
  justify-content: flex-end;
  font-size: 25rpx;
  margin: 0 20rpx 30rpx 0;
}

.di_ksxf {
  background-color: rgb(131, 199, 154);
  border-radius: 4px; /* 圆角设置为20px */
  padding: 10rpx 20rpx 10rpx 20rpx;
  margin-right: 20rpx;
  color: rgb(255, 255, 255);
  display: flex;
  justify-content: center;
  align-items: center;
}

.di_jsxf {
  border: 1rpx solid rgb(204, 204, 204);
  display: flex;
  justify-content: flex-end;
  font-size: 25rpx;
  margin: 0 20rpx 30rpx 0;
  padding: 8rpx 20rpx;
  border-radius: 6rpx;
}

.di_xf {
  background-color: rgb(131, 199, 154);
  border-radius: 4px; /* 圆角设置为20px */
  margin: 0 20rpx 30rpx 0;
  padding: 8rpx 47.5rpx;
  color: rgb(255, 255, 255);
}

.kk_di1 {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 25rpx;
  margin: 0 20rpx 10rpx 0;
}

.tubiao {
  width: 35rpx;
  height: 35rpx;
  margin-left: 5rpx;
}

.di_ksxf1 {
  border: 1rpx solid rgb(131, 199, 154);
  border-radius: 4px; /* 圆角设置为20px */
  padding: 5rpx 10rpx 5rpx 10rpx;
  margin-right: 20rpx;
  color: rgb(131, 199, 154);
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
